package com.ts.manage.cms.controller;

import com.ts.api.manage.cms.CmsPageControllerApi;
import com.ts.framework.domain.cms.CmsPage;
import com.ts.framework.domain.cms.request.QueryPageRequest;
import com.ts.framework.domain.cms.response.CmsPageResult;
import com.ts.framework.model.response.QueryResponseResult;
import com.ts.framework.model.response.ResponseResult;
import com.ts.manage.cms.service.CmsPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("cms/page")
public class CmsPageController implements CmsPageControllerApi {
    @Autowired
    private CmsPageService cmsPageService;

    /**
     * 根据条件分页查询页面信息
     * @param page
     * @param size
     * @param queryPageRequest
     * @return
     */
    @Override
    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult findCmsPageByPage(@PathVariable("page") Integer page,
                                                 @PathVariable("size") Integer size,
                                                 QueryPageRequest queryPageRequest) {
        return cmsPageService.findCmsPageByPage(page, size, queryPageRequest);
    }

    /**
     * 新增页面信息
     * @param cmsPage
     * @return
     */
    @Override
    @PostMapping("/add")
    public CmsPageResult addCmsPage(@RequestBody CmsPage cmsPage) {
        return cmsPageService.addCmsPage(cmsPage);
    }

    /**
     * 查询站点信息
     * @return
     */
    @Override
    @GetMapping("/cmsSite")
    public QueryResponseResult querySiteId() {
        return cmsPageService.querySiteId();
    }

    /**
     * 查询模板信息
     * @return
     */
    @Override
    @GetMapping("/cmsTemplate")
    public QueryResponseResult queryTemplate() {
        return cmsPageService.queryTemplate();
    }

    /**
     * 根据ID查询页面
     * @param id
     * @return
     */
    @Override
    @GetMapping("/get/{id}")
    public CmsPageResult findCmsPageById(@PathVariable String id) {
        return cmsPageService.findCmsPageById(id);
    }

    /**
     * 更新页面信息
     * @param id
     * @param cmsPage
     * @return
     */
    @Override
    @PutMapping("/edit/{id}")
    public CmsPageResult updateCmsPage(@PathVariable String id, @RequestBody CmsPage cmsPage) {
        return cmsPageService.updateCmsPage(id,cmsPage);
    }

    /**
     * 删除页面信息
     * @param id
     * @return
     */
    @Override
    @DeleteMapping("/del/{id}")
    public ResponseResult deleteCmsPageById(@PathVariable String id) {
        return cmsPageService.deleteCmsPageById(id);
    }
}
